/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package it.coraci.anag.db.mongo.entities;

import it.coraci.anag.gui.components.basic.annotations.GuiParam;
import it.coraci.anag.gui.components.basic.annotations.GuiParamFilePath;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.persistence.Basic;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MapKey;
import org.eclipse.persistence.nosql.annotations.DataFormatType;
import org.eclipse.persistence.nosql.annotations.Field;
import org.eclipse.persistence.nosql.annotations.NoSql;

/**
 *
 * @author Luca
 */
@Entity
@NoSql(dataFormat=DataFormatType.MAPPED)
public class MongoDocument implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Field(name="_id")
    private String id;
    @GuiParam(label = "Note" , type = GuiParam.GuiParamType.TEXT)
    @Basic
    private String notes;
//    @OneToMany
//    @JoinColumn(insertable = false, updatable = false)
//    @MapKeyJoinColumn()
//    
//    @ElementCollection
//   @MapKey(name = "name")
//    private Map<String,Attribute> values = new HashMap<>();
    @GuiParamFilePath(pastePath = "file_storage")
    @GuiParam(type = GuiParam.GuiParamType.TEXT, label = "File")
    private String filePath;

    @ElementCollection
    @MapKey(name = "key")
    @GuiParam(label = "Attributi", type = GuiParam.GuiParamType.MONGO_SPECIAL)
    private List<Attribute> values = new ArrayList<>();

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public List<Attribute> getValues() {
        return values;
    }

    public void setValues(List<Attribute> values) {
        this.values = values;
    }
    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MongoDocument)) {
            return false;
        }
        MongoDocument other = (MongoDocument) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.coraci.anag.db.mongo.entities.MongoDocument[ id=" + id + " ]";
    }
    
}
